#include <gflags/gflags.h>

#include "data/es.hpp"

DEFINE_bool(run_mode, true, "是否为调试模式");
DEFINE_string(log_file, "", "发布模式下，用于指定日志的输出文件");
DEFINE_int32(log_level, 0, "发布模式下，用于指定日志输出等级");

DEFINE_string(es_host, "http://127.0.0.1:9200/", "es服务器URL");

int main(int argc, char *argv[])
{
    google::ParseCommandLineFlags(&argc, &argv, true);
    im::initLogger(FLAGS_run_mode, FLAGS_log_file, FLAGS_log_level);

    auto es_client = im::ESClientFactory::create({FLAGS_es_host});

    im::ESMessage es_msg = im::ESMessage(es_client);

    es_msg.createIndex();

    es_msg.appendData("用户ID1", "消息ID1", "会话ID1", "这是一只边牧狗", time(nullptr));
    es_msg.appendData("用户ID2", "消息ID2", "会话ID1", "这是一只吉娃娃狗", time(nullptr) - 60);


    auto result = es_msg.search("会话ID1", "狗");
    for (auto &m : result) {
        std::cout << "-----------------" << std::endl;
        std::cout << m.user_id() << std::endl;
        std::cout << m.message_id() << std::endl;
        std::cout << m.session_id() << std::endl;
        std::cout << m.content() << std::endl;
        std::cout << boost::posix_time::to_simple_string(m.create_time()) << std::endl;
    }

    es_msg.remove("消息ID2");

    return 0;
}